﻿using CardPlay.Model.ActionModel;
using CardPlay.Model.CardModel;
using CardPlay.Model.GameModel;
using CardPlay.Model.GameModel.Actions;

namespace CardPlay.DemoPack.Games.FortyThievesVariants
{
    [Game("E12D6C5E-92A0-4162-A70A-54638A8BB300", LevelOfDifficulty.Medium, LevelOfSkill.MostlyChance, DurationOfPlay.MoreThan10Minutes, NumberOfDecks = 2, Family = FamilyName)]
    public class Blockade : FortyThieves
    {
        public Blockade()
        {
            MaximumDeals = 1;
            TotalTableaus = 12;
            TableauDealFormat = "1 up";
            TableauBuildSequence = CardFaceSequence.SameSuitDescendingRank;
        }

        protected override bool AllowedToPickupAtTableau(RemovePileAction action)
        {
            return action.IsActingOnFaceUpTopPileInSequence(TableauBuildSequence);
        }

        protected override IAction QueryActionAt(PartLocation location)
        {
            var card = CardAt(location);
            if (card == null) return null;

            return location.Matches(Stock) && location.Index == this[Stock].TopIndex
                ? new DealOutTableauAction(this, location)
                : base.QueryActionAt(location);
        }

        protected override void OnTransactionEnding()
        {
            this.FillFromStockEmptyPilesMatching(AnyTableau);
        }
    }
}
